package com.bykj.property.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bykj.property.controller.vo.request.RepairOrderPageRequest;
import com.bykj.property.mapper.PmUnitMapper;
import com.bykj.property.mapper.PmVillageMapper;
import com.bykj.property.model.PmProprietor;
import com.bykj.property.model.RepairOrder;
import com.bykj.property.mapper.RepairOrderMapper;
import com.bykj.property.service.RepairOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* <p>
    * 报修信息表 服务实现类
    * </p>
*
* @author liangyiming
* @since 2019-07-23
*/
@Service
public class RepairOrderServiceImpl extends ServiceImpl<RepairOrderMapper, RepairOrder> implements RepairOrderService {
@Autowired
private RepairOrderMapper mapper;
@Autowired
private PmVillageMapper pmVillageMapper;
@Autowired
private PmUnitMapper pmUnitMapper;
@Override
public Page<RepairOrder> queryPage(RepairOrderPageRequest pageRequest) {
    Page<RepairOrder> orderPage=mapper.queryPage(pageRequest);
    List<RepairOrder> orders=orderPage.getRecords();
    orders.forEach(m->{
        PmProprietor pmProprietor=m.getPmProprietor();
        pmProprietor.setPmVillage(pmVillageMapper.selectById(pmProprietor.getPmVillageId()));
        pmProprietor.setPmUnit(pmUnitMapper.selectById(pmProprietor.getPmUnitId()));
    });
    return orderPage;
    }

    @Override
    public int saveTokey(RepairOrder repairOrder) {
        return mapper.saveToKey(repairOrder);
    }
}